package com.telit.firecommand.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.telit.common.entity.DataReturn;
import com.telit.common.enums.ResultCode;
import com.telit.common.exception.ForestBaseException;
import com.telit.common.util.JwtTokenUtils;
import com.telit.communicate.feign.RemoteCommunicateService;
import com.telit.firecommand.dao.CommFireAlarmDao;
import com.telit.firecommand.dao.CommMsgCenterLogDao;
import com.telit.firecommand.dto.*;
import com.telit.firecommand.entity.CommFireAlarm;
import com.telit.firecommand.entity.FileUploadLog;
import com.telit.firecommand.facade.FireTriggerFacadeService;
import com.telit.firecommand.facade.SmsPushUriPubFacadeService;
import com.telit.firecommand.facade.VoicePushFacadeService;
import com.telit.firecommand.service.*;
import com.telit.firecommand.service.impl.FireDisposeServiceImpl;
import com.telit.firecommand.service.impl.MsgCenterService;
import com.telit.upms.vo.MicroSysUserAllInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @author chencf
 * @description 火情管理接口
 */
@RestController
@RequestMapping("/fire-manager")
@Api(tags = "火情管理接口", description = "/fire-manager")
@Slf4j
public class FireManagerController {


    @Autowired
    private FireManagerService fireManagerService;

    @Autowired
    private FireQueryService fireQueryService;

    @Autowired
    private CommFireAlarmDao commFireAlarmDao;

    @Autowired
    private FireDisposeServiceImpl fireDisposeService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private MsgService msgService;

    @Autowired
    private FireAdminService fireAdminService;

    @Autowired
    private CommMsgCenterLogDao commMsgCenterLogDao;

//    @Autowired
//    private OperationFeignClient operationFeignClient;

    @Autowired
    private SmsPushUriPubFacadeService smsPushUriPubFacadeService;

    @Autowired
    private MsgCenterService msgCenterService;

    @Autowired
    private RemoteCommunicateService communicateFeignClient;

    @Autowired
    private FireTriggerFacadeService fireTriggerFacadeService;

    @Autowired
    private VoicePushFacadeService voicePushFacadeService;

    @Value("${forest.enablePushFireSms}")
    private String enablePushFireSms;

    @PostMapping("/addTelephoneAlarmFireByWeb")
    @ApiOperation("web端添加电话接警,已有火情传originFireId字段")
    public DataReturn addTelephoneAlarmFireByWeb(@RequestBody(required = true) CommFireAlarm commFireAlarm, HttpServletRequest httpServletRequest) throws Exception {
        if (commFireAlarm.getFinderName() == null || commFireAlarm.getFindTime() == null) {
            return DataReturn.failure(ResultCode.REQUEST_PARAMS_CHECK_ERROR);
        }
        commFireAlarm.setResource("6");
        commFireAlarm.setAction("1");
        commFireAlarm.setStatus("1");
        //fireManagerService.addFire(commFireAlarm, httpServletRequest);
        fireTriggerFacadeService.addFire(commFireAlarm, httpServletRequest);
        RecordScene telephoneAlarm = new TelephoneAlarm();
        telephoneAlarm.setFireId(commFireAlarm.getId());
        Long id = JwtTokenUtils.getId();
        MicroSysUserAllInfoVo microSysUserAllInfoVo = userInfoService.getUserInfo(id);
        fireDisposeService.processDisposeInfo(telephoneAlarm, microSysUserAllInfoVo);
        return DataReturn.ok("添加成功");

    }


    @PostMapping(value = "/addFireInfoByApp", produces = "application/json;charset=UTF-8")
    @ApiOperation("护林员和飞手app端调用上报火情 护林员上报resource传1 飞手上报resource传2")
    public DataReturn addFireInfoByApp(@RequestBody CommFireAlarm commFireAlarm, HttpServletRequest httpServletRequest) throws Exception {
        Long id = JwtTokenUtils.getId();
        String name = JwtTokenUtils.getRealName();
        commFireAlarm.setFinderId(id);
        commFireAlarm.setFinderName(name);
        commFireAlarm.setFindTime(new Date());
        commFireAlarm.setStatus("1");
        commFireAlarm.setAction("1");
        //fireManagerService.addFire(commFireAlarm, httpServletRequest);
        fireTriggerFacadeService.addFire(commFireAlarm, httpServletRequest);
        return DataReturn.ok();
    }

    @PostMapping("/addFireByWebAdministrator")
    @ApiOperation("防火管理员web端手工添加火情,1. 疑似火情 status字段传1； 2.真实火情 status字段传3；3.非应急演练 action传1 ，应急演练 action字段传2")
    public DataReturn addFireByWebAdministrator(@RequestBody CommFireAlarm commFireAlarm, HttpServletRequest httpServletRequest) throws Exception {
        if (commFireAlarm.getStatus() == null) {
            return DataReturn.failure(ResultCode.REQUEST_PARAMS_CHECK_ERROR);
        }
        commFireAlarm.setResource("7");
        Long id = JwtTokenUtils.getId();
        MicroSysUserAllInfoVo userInfo = userInfoService.getUserInfo(id);
        commFireAlarm.setFinderId(id);
        commFireAlarm.setFinderName(userInfo.getRealName());
        fireManagerService.addFire(commFireAlarm, httpServletRequest);
        fireTriggerFacadeService.addFire(commFireAlarm, httpServletRequest);
        RecordScene recordScene = null;
        if ("1".equals(commFireAlarm.getAction())) {
            recordScene = new AddFireByWebAdmin();
        } else if ("2".equals(commFireAlarm.getAction())) {
            recordScene = new AddEmergencyDrillByWebAdmin();
        }
        //做非空判断，质量检测出来会有空指针的情况，但是只要插入代码执行正常，ID是不可能为null的
        if(ObjectUtil.isNotEmpty(commFireAlarm.getId())) {
            recordScene.setFireId(commFireAlarm.getId());
        }
//        SysUserDetailVo sysUserDetailVo = new SysUserDetailVo();
//        sysUserDetailVo.setRealName(commFireAlarm.getFinderName());
//        sysUserDetailVo.setDeptName(commFireAlarm.getDistrictName());
        fireDisposeService.processDisposeInfo(recordScene, userInfo);

        // 给防火管理推送火情报警消息提醒,如果是真实火情就发送短信
       /* if ("3".equals(commFireAlarm.getStatus()) && "true".equals(enablePushFireSms)) {
            msgService.pushFireAlarmSms(fireAdminService.fireMangerMobileList(), commFireAlarm.getDistrictName());

            List<String> list = fireAdminService.fireMangerIdList();
            String content = commFireAlarm.getDistrictName() + "发现了真实火情,请及时组织扑火工作";
            String title = "发现真实火情";
            AliyunPushMessageUtils.customizeAdvancedPush(new AliPushMessagePojo(MsgConstants.TARGET_ACCOUNT, MsgConstants.PUSH_TYPE_MESSAGE, MsgConstants.DEVICE_TYPE_ANDROID, title, list,
                    new AliPushContentPojo(NoticeTypeConstants.NOTICE_TYPE_NORMAL, JSON.toJSONString(content))));
            list.forEach(e -> {
                CommMsgCenterLog log = new CommMsgCenterLog(content, "4", new Date(), "1", userInfo.getRealName(), title, Long.parseLong(e));
                commMsgCenterLogDao.insert(log);
            });
        }*/

        return DataReturn.ok("添加成功");
    }

    @GetMapping("/confirmCameraFindFire")
    @ApiOperation("判别监控发现火情（0.待判别 1.真实火情 2.疑似火情 3.误报）")
    public DataReturn JudgmentCameraFindFire(@RequestParam(required = true) Long fireId, @RequestParam(required = true) Integer fireJudgmentType) {
        try {
            Long id = JwtTokenUtils.getId();
            fireManagerService.judgmentCameraFindFire(fireId, fireJudgmentType);
            return DataReturn.ok("火情判别成功");
        } catch (Exception e) {
            e.printStackTrace();
            return DataReturn.failure(ResultCode.SERVER_ERROR, e.getMessage());
        }
    }


    @GetMapping("/setAsRepeatedFire")
    @ApiOperation("设为重复火情")
    public DataReturn setAsRepeatedFire(@RequestParam(required = true) Long sourceFireId, @RequestParam(required = true) Long repeatFireId, HttpServletRequest httpServletRequest) {
        if (!fireQueryService.queryIsExist(sourceFireId) || !fireQueryService.queryIsExist(repeatFireId)) {
            return DataReturn.failure(ResultCode.OPERATE_ERROR.getCode(), "火情不存在！");
        }

        Long id = JwtTokenUtils.getId();
        MicroSysUserAllInfoVo userInfo = userInfoService.getUserInfo(id);
        SetRepeatFire setRepeatFire = new SetRepeatFire();
        CommFireAlarm commFireAlarm = fireQueryService.queryById(repeatFireId);
//        setRepeatFire.setFireId(commFireAlarm.getId());
        setRepeatFire.setFireId(sourceFireId);
        setRepeatFire.setCommFireAlarm(commFireAlarm);
        fireDisposeService.processDisposeInfo(setRepeatFire, userInfo);

        fireManagerService.setAsRepeatedFire(sourceFireId, repeatFireId, httpServletRequest);


        return DataReturn.ok("设置成功");
    }

//    /**
//     * 2022-04-21 fix by tracine: 用 get 请求方式会导致请求地址参数超出允许范围，出现未知错误
//     */
//    @PostMapping("confirmFire")
//    @ApiOperation("确认火情(待核实状态调用,1确认火情 2确认误报 3设为应急演练)")
//    public DataReturn confirmFire(@RequestBody @Validated ConfirmFireVo vo, HttpServletRequest httpServletRequest) throws Exception {
//        fireManagerService.confirmFire(vo.getFireId(), vo.getConfirmType(), vo.getDescription(), httpServletRequest);
//
//        Long id = JwtTokenUtils.getId();
//        SysUserDetailVo userInfo = userInfoService.getUserInfo(id);
//        if ("1".equals(vo.getConfirmType())) {
//            ConfirmRealFire confirmRealFire = new ConfirmRealFire();
//            confirmRealFire.setFireId(vo.getFireId());
//            fireDisposeService.processDisposeInfo(confirmRealFire, userInfo);
//
//            // 给防火管理员发送预警短信
//            CommFireAlarm commFireAlarm = fireQueryService.queryById(vo.getFireId());
//            if (commFireAlarm != null && StringUtils.isNotBlank(commFireAlarm.getDistrictName()) && "true".equals(enablePushFireSms)) {
//                msgService.pushFireAlarmSms(fireAdminService.fireMangerMobileList(), commFireAlarm.getDistrictName());
//
//                List<String> list = fireAdminService.fireMangerIdList();
//                String content = commFireAlarm.getDistrictName() + "发现了真实火情,请及时组织扑火工作";
//                String title = "发现真实火情";
//                AliyunPushMessageUtils.customizeAdvancedPush(new AliPushMessagePojo(MsgConstants.TARGET_ACCOUNT, MsgConstants.PUSH_TYPE_MESSAGE, MsgConstants.DEVICE_TYPE_ANDROID, title, list,
//                    new AliPushContentPojo(NoticeTypeConstants.NOTICE_TYPE_NORMAL, JSON.toJSONString(content))));
//                list.forEach(e -> {
//                    CommMsgCenterLog log = new CommMsgCenterLog(content, "4", new Date(), "1", commFireAlarm.getFinderName(), title, Long.parseLong(e));
//                    commMsgCenterLogDao.insert(log);
//                });
//            }
//        } else if ("2".equals(vo.getConfirmType())) {
//            ConfirmFakeFire confirmFakeFire = new ConfirmFakeFire();
//            confirmFakeFire.setFireId(vo.getFireId());
//            confirmFakeFire.setFakeDesc(vo.getDescription());
//            fireDisposeService.processDisposeInfo(confirmFakeFire, userInfo);
//        } else if ("3".equals(vo.getConfirmType())) {
//            SetEmergencyDrill setEmergencyDrill = new SetEmergencyDrill();
//            setEmergencyDrill.setFireId(vo.getFireId());
//            fireDisposeService.processDisposeInfo(setEmergencyDrill, userInfo);
//        }
//        return DataReturn.ok("设置成功");
//    }

    @GetMapping("/confirmFire")
    @ApiOperation("确认火情(待核实状态调用,1确认火情 2确认误报 3设为应急演练)")
    public DataReturn confirmFire(@RequestParam(required = true) Long fireId, @RequestParam(required = true) String confirmType, @RequestParam(required = false) String description, @RequestParam(value = "mediaUrl", required = false) String mediaUrl, @RequestParam(value = "faketype", required = false) String faketype, HttpServletRequest httpServletRequest) throws Exception {
        //2022-04-17 临时处理
//        if (StringUtils.isNotEmpty(description)) {
//            if (description.length() > 500) {
//                return new DataReturn(ResultCode.FORM_PARAMS_CHECK_ERROR, "输入的内容超过500字", null);
//            }
//        }

        fireManagerService.confirmFire(fireId, confirmType, description, mediaUrl, faketype, httpServletRequest);

        Long id = JwtTokenUtils.getId();
        MicroSysUserAllInfoVo userInfo = userInfoService.getUserInfo(id);
        if ("1".equals(confirmType)) {
            ConfirmRealFire confirmRealFire = new ConfirmRealFire();
            confirmRealFire.setFireId(fireId);
            fireDisposeService.processDisposeInfo(confirmRealFire, userInfo);

            // 给防火管理员发送预警短信
//            CommFireAlarm commFireAlarm = fireQueryService.queryById(fireId);
////            if (commFireAlarm != null && StringUtils.isNotBlank(commFireAlarm.getDistrictName()) && "true".equals(enablePushFireSms)) {
//            if (commFireAlarm != null && "true".equals(enablePushFireSms)) {
//                try {
//                    //真实火情推送人员手机号集合
//                    final List<String> pushRealFireMobileList = CollUtil.<String>newArrayList();
//                    //防火管理员手机号集合
//                    final  List<String> fireMangerMobileList = CollUtil.<String>newArrayList();
//                    //根据行政区划查询防火管理员手机号集合（包含浦口区防火管理员）
//                    if (commFireAlarm.getDistrictCode() != null && commFireAlarm.getDistrictCode().length() >= 9) {
//                        fireMangerMobileList.addAll(fireAdminService.fireMangerMobileListByDistrictCode(commFireAlarm.getDistrictCode().substring(0, 9)));
//                    } else {
//                        fireMangerMobileList.addAll(fireAdminService.fireMangerMobileList());
//                    }
//                    if (fireMangerMobileList != null && fireMangerMobileList.size() > 0) {
//                        //防火管理员手机号集合添加到真是火情推送人员手机集合
//                        pushRealFireMobileList.addAll(fireMangerMobileList);
//                    }
//                    /*//真实火情推送人员手机号集合
//                    List<String> pushRealFireMobileList = new ArrayList<>();
//                    //防火管理员手机号集合
//                    List<String> fireMangerMobileList = fireAdminService.fireMangerMobileList();
//                    if (fireMangerMobileList != null && fireMangerMobileList.size() > 0) {
//                        //防火管理员手机号集合添加到真是火情推送人员手机集合
//                        pushRealFireMobileList.addAll(fireMangerMobileList);
//                    }*/
//                    //查询火情报警消息提醒手机号列表
//                    try {
////                        DataReturn dataReturn = operationFeignClient.mobileListByType("4");
////                        if (dataReturn.getData() != null) {
////                            //系统管理模块配置的“火情报警消息提醒”中的人员手机号集合添加到真是火情推送人员手机集合
////                            pushRealFireMobileList.addAll((List<String>) dataReturn.getData());
////                        }
//                    }catch (Exception e){
//                        e.printStackTrace();
//                    }
//
//                    //todo 更正真实火情推送模版业务逻辑
//                    //                msgService.pushFireAlarmSms(pushRealFireMobileList, commFireAlarm.getDistrictName());
//                    smsPushUriPubFacadeService.sendSms(fireId, pushRealFireMobileList, 1);
//
//                    //TODO 推送给防火管理员疑似火情的语音提醒
//                    boolean voiceBool = voicePushFacadeService.pushVoice(commFireAlarm.getId(), fireMangerMobileList, 1);
//                    if(!voiceBool){
//                        log.error("调用阿里发送语音失败");
//                    }
//
//                } catch (Exception e) {
//                    log.error("获得手机号类型为4的短信推送失败,原因[{}]", e.getMessage());
//                }
//
//
//                try {
//                    //查询行政区划及以上防火管理员的ID集合
//                    final List<String> fireMangerIdList = CollUtil.<String>newArrayList();
//                    if (commFireAlarm.getDistrictCode() != null && commFireAlarm.getDistrictCode().length() >= 9) {
//                        fireMangerIdList.addAll(fireAdminService.fireMangerIdListByDistrictCode(commFireAlarm.getDistrictCode().substring(0, 9)));
//                    } else {
//                        fireMangerIdList.addAll(fireAdminService.fireMangerIdList());
//                    }
////                    List<String> list = fireAdminService.fireMangerIdList();
//                    String content = commFireAlarm.getDistrictName() + "发现了真实火情,请及时组织扑火工作";
//                    String title = "火情报警";
//                    PushResponse pushResponse = AliyunPushMessageUtils.customizeAdvancedPush(new AliPushMessagePojo(MsgConstants.TARGET_ACCOUNT, MsgConstants.PUSH_TYPE_MESSAGE, MsgConstants.DEVICE_TYPE_ANDROID, title, fireMangerIdList,
//                            new AliPushContentPojo(NoticeTypeConstants.NOTICE_TYPE_NORMAL, JSON.toJSONString(content))));
//                    if (ObjectUtil.isNull(pushResponse)) {
//                        throw new Exception("阿里云短信通知推送失败!");
//                    } else {
//                        log.info("阿里推送消息{}", JSONUtil.toJsonStr(pushResponse));
//                    }
//                    fireMangerIdList.forEach(e -> {
//                        CommMsgCenterLog log = new CommMsgCenterLog(content, "4", new Date(), "1", commFireAlarm.getFinderName(), title, Long.parseLong(e));
//                        commMsgCenterLogDao.insert(log);
//                    });
//                } catch (Exception e) {
//                    log.error(e.getMessage());
//                }
//
//                //此业务已经作为疑似推送过一次，确认后可以不推
//               /* try {
//                    //确认火情为真实火情推送web端
//                    final DataReturn websocketDataReturn = communicateFeignClient.sendMsg(new SendMessageDTO("WEB", JSON.toJSONString(DataReturn.ok(MsgIdentificationConstants.FIRE_ALARM, null))));
//                    if (ObjectUtil.isNull(websocketDataReturn)) {
//                        throw new Exception("微服务调用推送websocket失败");
//                    }
//                    if (StrUtil.equals(websocketDataReturn.getCode(), ResultCode.SUCCESS.getCode())) {
//                        log.info("websocket推送火情成功!");
//                    } else {
//                        throw new Exception(StrUtil.format("code:[{}],errMsg:[{}]", websocketDataReturn.getCode(), websocketDataReturn.getErrorMsg()));
//                    }
//                } catch (Exception e) {
//                    log.error("websocket 推送火情失败，原因是:[{}]", e.getMessage());
//                }*/
//            }
        } else if ("2".equals(confirmType)) {
            ConfirmFakeFire confirmFakeFire = new ConfirmFakeFire();
            confirmFakeFire.setFireId(fireId);
            confirmFakeFire.setFakeDesc(description);
            fireDisposeService.processDisposeInfo(confirmFakeFire, userInfo);
        } else if ("3".equals(confirmType)) {
            SetEmergencyDrill setEmergencyDrill = new SetEmergencyDrill();
            setEmergencyDrill.setFireId(fireId);
            fireDisposeService.processDisposeInfo(setEmergencyDrill, userInfo);
        }
        return DataReturn.ok("设置成功");
    }

    @GetMapping("/reportToSuperior")
    @ApiOperation("火情上报")
    public DataReturn reportToSuperior(@RequestParam(required = true) Long fireId, HttpServletRequest httpServletRequest) {
        fireManagerService.reportToSuperior(fireId, httpServletRequest);
        return DataReturn.ok("上报成功");
    }

    /**
     * 2022-08-29增加flag，目的是安卓端传递flag不为空的时候，标识修改状态是安卓端发出的，需要实时推送火情状态变更消息给web端，让web端同步修改
     * @param fireId 火情ID
     * @param status 修改的状态码
     * @param flag  不为空代表是安卓端进行修改
     * @param httpServletRequest
     * @return
     */
    @GetMapping("/changeFireStatus")
    @ApiOperation("火情状态修改 1:待接警 2待核实 3待处置 4处置中 5已处置 6误报")
    public DataReturn changeFireStatus(@RequestParam(required = true) Long fireId,
                                       @RequestParam(required = true) String status,
                                       @RequestParam(required = false) String flag,
                                       HttpServletRequest httpServletRequest) {
        try {
            //根据火情ID查询火情详细信息
            CommFireAlarm commFireAlarm = fireQueryService.queryById(fireId);
            //判断该条火情当前状态和修改状态是否一致
            if (status.equals(commFireAlarm.getStatus())) {
                //如果一致，代表有人修改过此火情的状态，直接返回修改成功；同时处置信息中仍然是第一次进行修改的那个人的相关信息
                return DataReturn.ok("火情状态修改成功");
            }
            //修改本条火情的处置状态
            fireManagerService.changeFireStatus(fireId, status, httpServletRequest);

            Long id = JwtTokenUtils.getId();
//            Long id = 1524651793085190146L;
            MicroSysUserAllInfoVo userInfo = userInfoService.getUserInfo(id);
            RecordScene recordScene = null;
            if ("2".equals(status)) {
                recordScene = new ReceiveAlarm();
            } else if ("4".equals(status)) {
                recordScene = new ProcessFire();
            } else if ("5".equals(status)) {
                recordScene = new FinishDispose();
            }
            recordScene.setFireId(fireId);
            fireDisposeService.processDisposeInfo(recordScene, userInfo);

            //火情接警APP通知推送
            //根据火情来源判断是护林员或者飞手
//            if (commFireAlarm != null && StrUtil.equals(status,"2") ) {
//                if ("1".equals(commFireAlarm.getResource()) || "2".equals(commFireAlarm.getResource())) {
//                    String title = "你的上报火情已接警";
//                    Map<String, Object> contentMap = new HashMap<>();
//                    contentMap.put("fireId", fireId);
//                    //格式化发现时间
//                    String findTime = "";
//                    if (commFireAlarm.getFindTime() != null) {
//                        findTime = DateUtil.format(commFireAlarm.getFindTime(), "yyyy-MM-dd HH:mm");
//                    }
//
//                    //获取详细地址
//                    String detailAddress = commFireAlarm.getDetailAddress() == null ? "" : commFireAlarm.getDetailAddress();
//                    //获取接警人姓名
//                    String realName = "";
//                    if (userInfo != null) {
//                        realName = userInfo.getRealName() == null ? "" : userInfo.getRealName();
//                    }
//                    String content = "你在" + findTime + "上报的" + detailAddress + "的火情已被防火管理员" + realName + "接警,请前往查看";
//                    contentMap.put("content", content);
//                    //获取发现者ID，把消息推送给发现者
//                    if (commFireAlarm.getFinderId() != null && commFireAlarm.getFinderId() != 0) {
//                        //推送app通知给发现者
//                        String findIdStr = Convert.toStr(commFireAlarm.getFinderId());
//                        List<String> findIdList = new ArrayList<>();
//                        findIdList.add(findIdStr);
//                        AliyunPushMessageUtils.customizeAdvancedPush(new AliPushMessagePojo(MsgConstants.TARGET_ACCOUNT, MsgConstants.PUSH_TYPE_MESSAGE, MsgConstants.DEVICE_TYPE_ANDROID, title, findIdList,
//                                new AliPushContentPojo(NoticeTypeConstants.NOTICE_TYPE_CENTER_MSG, JSON.toJSONString(contentMap))));
//                        //消息中心保存
//                        msgCenterService.addBatch(new CommMsgCenterLogDTO(content, "3", new Date(), "1", realName, title, Convert.toList(Long.class, commFireAlarm.getFinderId())));
//                    }
//
//
//                }
//            }

            //查找当前火情被合并的火情的ID集合
            List<Long> fireAlarmIdList = commFireAlarmDao.queryAllFireAlarmByOrginId(fireId);
            //被合并的火情ID集合非空判断
            if (fireAlarmIdList != null && fireAlarmIdList.size() > 0) {
                for (Long fireAlarmId :
                        fireAlarmIdList) {
                    //修改源为本条火情的其他火情的处置状态
                    fireManagerService.changeFireStatus(fireAlarmId, status, httpServletRequest);
                   /* //根据产品要求A火情不再更新处置信息
                    //记录被合并的火情的处置信息
                    recordScene.setFireId(fireAlarmId);
                    //处置信息更新
                    fireDisposeService.processDisposeInfo(recordScene, userInfo);*/
                }
            }

            //判断如果flag不为空，推送消息给web端更改火情状态
            pushFireStatusMsg(flag,status,commFireAlarm);

             return DataReturn.ok("火情状态修改成功");
        } catch (ForestBaseException e) {
            return DataReturn.failure(e.getStatus(), e.getDefaultMessage());
        } catch (Exception e) {
            return DataReturn.failure(ResultCode.SERVER_ERROR);
        }
    }

    @Async
    void pushFireStatusMsg(String flag,String status,CommFireAlarm fireAlarm) {
        try {
            // 判断如果flag不为空，推送消息给web端更改火情状态
            if (StrUtil.isNotEmpty(flag)) {
                //查询行政区划及以上防火管理员的ID集合
                final List<String> fireMangerIdList = CollUtil.<String>newArrayList();
                if (fireAlarm.getDistrictCode() != null && fireAlarm.getDistrictCode().length() >= 9) {
                    fireMangerIdList.addAll(fireAdminService.fireMangerIdListByDistrictCode(fireAlarm.getDistrictCode().substring(0, 9)));
                } else {
                    fireMangerIdList.addAll(fireAdminService.fireMangerIdList());
                }
                if (fireMangerIdList != null && fireMangerIdList.size() > 0) {
                 //   communicateFeignClient.sendMsg(new SendMessageDTO("WEBWITHINUSERID", Convert.toStrArray(fireMangerIdList), JSON.toJSONString(DataReturn.ok(MsgIdentificationConstants.FIRE_STATUS_UPDATE, status))));
                }
            }
        }catch (Exception e){
            log.error("修改火情状态：{},推送失败",status);
        }

    }


    @PostMapping(value = "/updateFireRegionalInfo", produces = "application/json;charset=UTF-8")
    @ApiOperation("更新火情地区信息")
    public DataReturn updateFireRegionalInfo(@RequestBody CommFireAlarm commFireAlarm,
                                             HttpServletRequest httpServletRequest) throws Exception {
        fireManagerService.updateFireRegionalInfo(commFireAlarm, httpServletRequest);
        return DataReturn.ok();
    }

    @PostMapping("/saveFireFiles")
    @ApiOperation("/保存火情图片")
    public DataReturn<?> saveFireFiles(@RequestBody List<FileUploadLog> fireFiles) {
        fireManagerService.saveFireFiles(fireFiles);
        return DataReturn.ok();
    }

    @PostMapping("/update-fire-info")
    @ApiOperation("/修改火情信息")
    public DataReturn<?> updateFireInfo(@RequestBody CommFireAlarm commFireAlarm) {
        fireManagerService.updateFireInfo(commFireAlarm);
        return DataReturn.ok();
    }

}
